import time
import subprocess
from xiaopy import *
from cotc import COTC

subprocess.run(["su", "root"])

try:
    ui = xp.ui()
    region = ui.stringValue("region")
    c = COTC(region)
except Exception as e:
    xp.toast(e)


def run_script():
    time.sleep(0.5)
    print("寻找可点击对象……")
    if not c.tap_sheep():
        print("长时间未找到点击对象，脚本结束。")
        return

    time.sleep(1)
    print("检查获取物品……")
    if not c.wait_item_obtain():
        print("点击对象有误，脚本结束。")
        return

    if c.check_fleece_obtain():
        print("--获取三毛--")
        xp.tap(640, 433)
        time.sleep(1)
    else:
        print("--获取失败--")
        c.restart_cotc()
    run_script()


run_script()
